package com.zhu.transaction.utils;

import com.zhu.transaction.pojo.state.R;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.util.Objects;

/**
 * @author Zhu
 * @createtime 2021/2/10-20:27
 */
public class UploadImgUtils {

    public static String uploadImg(MultipartFile file, String path, String fileName) {
        String url = "";
        String originalFilename = file.getOriginalFilename();
        int lastIndex = Objects.requireNonNull(originalFilename).lastIndexOf(".");
        String suffix = originalFilename.substring(lastIndex);
        try {
            url = OssUtils.uploadFile(file.getInputStream(), path + "/" + fileName + suffix);
        } catch (IOException e) {
            e.printStackTrace();
        }
        return url;
    }
}
